<template>
	<view class="confirm" :class="{popupShow:popupShow}">
		<u-navbar
		          title="预约信息"
		          :autoBack="true"
		      >
		      </u-navbar>
		<view class="docinfo">
			<view class="docmain">
				<view class="docl" v-if="xiadaninfo.docimg">
					<!-- <image :src="xiadaninfo.docimg" mode="aspectFit"></image> -->
					<u-avatar :src="xiadaninfo.docimg" size="45" shape="circle" :default-url="log_pic"></u-avatar>
				</view>
				<view class="docl" v-if="!xiadaninfo.docimg">
					<image src="../../static/icons/yimo.png" mode="aspectFit"></image>
				</view>
				<view class="docr">
					<view class="docname">
						{{xiadaninfo.docname}} <span>{{xiadaninfo.doctitle}}</span>
					</view>
					<view class="hosname">
						{{xiadaninfo.hosname}} {{xiadaninfo.depart}}
					</view>
				</view>
			</view>
		</view>
		<view class="jiuinfo">
			<view class="jiumain">
				<view class="jiuitem">
					<view class="jiutit">
						就诊时间
					</view>
					<view class="jiui">
						{{xiadaninfo.serviceDate}} {{xiadaninfo.week}} {{xiadaninfo.wubie}}
						{{xiadaninfo.sourceStime}}-{{xiadaninfo.sourceEtime}}
					</view>
				</view>
				<view class="jiuitem " style="border: none;">
					<view class="jiutit">
						就诊人
					</view>
					<view class="jiui"
						style="color: #4581F6; font-size: 36rpx;display: flex;justify-content: space-between;"
						@click="chooseuser()">
						<view class="">
							{{name}}
						</view>
						<view class="">
							<u-icon name="arrow-right" color="#999" size="16"></u-icon>
						</view>
					</view>
				</view>
				<!-- <view class="jiuitem"  style="border: none; display: flex;justify-content: space-between;">
					<view class="jiutit">
						短信接收号码
					</view>
					<view class="jiui" style="font-size: 26rpx;">
						17637180187
					</view>
				</view> -->
			</view>
		</view>
		<view class="jiuxin">
			<view class="jiuxinmain">
				<view class="jiuxinitem" style="border-bottom: 1rpx solid #EEEEEE;">
					<view class="xiniteml">
						初/复诊
					</view>
					<view class="xinitemr" style="display: flex;" @click="choosechufu()">
					{{zhentype}}
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
				</view>
				<view class="jiuxinitem">
					<view class="xiniteml">
						诊查费用
					</view>
					<view class="xinitemr">
						{{xiadaninfo.totalFee}}元
					</view>
				</view>
				<view class="" style="display: flex; justify-content: flex-end;margin-top: -20rpx;">
					<u-icon name="info-circle" color="red"></u-icon><span
						style="color: #FF3D2F;font-size: 24rpx;">以当天医院取号窗口为准</span>
				</view>
				<view class="jiuxinitem">
					<view class="xiniteml">
						支付方式
					</view>
					<view class="xinitemr">
						医院现场支付
					</view>
				</view>
				<view class="jiuxinitem" style="border: none;" v-if="xiadaninfo.seeAddress">
					<view class="xiniteml">
						就诊地点
					</view>
					<view class="xinitemr">
						{{xiadaninfo.seeAddress?xiadaninfo.seeAddress:"暂无"}}
					</view>
				</view>
			</view>
		</view>
		<view class="wenxin" v-if="content.length>0">
			<p>重要提示：</p>
			<p v-for="item in content">  <rich-text :nodes="item"></rich-text></p>
			
		</view>
		<view class="btn" @click="confirm()">
			确认预约
		</view>
		<!-- <u-popup :show="showfu" mode="bottom" @close="closepopp()">
			<view class="btnlist">
				<view class="btnl" @click="closepopchu()">
					取消
				</view>
				<view class="btnr" @click="confirmchu()">
					确定
				</view>
			</view>
			<picker-view :value="value" @change="onChange" class="my-picker">
				<picker-view-column>
					<view v-for="item in chufulist">{{item}}</view>
				</picker-view-column>
			</picker-view>

		</u-popup> -->
		<u-picker @cancel="cancelfu" :show="showfu" :columns="columns" @confirm="chossefu"></u-picker>
		<u-popup :show="showname" mode="bottom" @close="closechufu()" :closeOnClickOverlay="true">
			<view class="popuser">
				<scroll-view scroll-y="true">
					<view class="userlist">
						<view class="useritem" @click="choosefa()">
							{{userinfo.name}}
						</view>
						<view class="useritem" v-for="item in childuserinfo" @click="choosechild(item)">
							{{item.name}}
						</view>
					</view>
				</scroll-view>

				<view class="line">

				</view>
				<view class="add" @click="goxinzneg()" v-if="childuserinfo.length<4">
					新增就诊人
				</view>
				<view class="cancel" @click="close()">
					取消
				</view>
			</view>
		</u-popup>
		<u-popup class="shouquan" customStyle="width:700rpx;" :show="showw" :round="10" mode="center" width="80%" :closeable="true" @close="closee" height="" border-radius="10">
			<view class="pop">
				<!-- <view class="poptop">
					<u-navbar :custom-back="cancell" :is-back="true" :title-bold="true" title="健康卡授权"></u-navbar>
				</view> -->
				<view class="cardimg">
					<image src="../../static/icons/cardicon.png" mode=""></image>
				</view>
				<view class="hosname">
					河南预约挂号平台
				</view>
				<view class="" v-if="showpp">
					<health-card-login encrypt="true" authLogin="false" @authFail="authFail" @authSucess="authSuccess" :authCancel="authCancel"
					 wechatcode="true">
						<view class="foott">
							<view @click="hideComponentLogin()" class="agree">一键登录授权</view>
						</view>
						<view class="shuomingg">
							登录代表同意<span @click="goxieyi()">《用户服务协议与隐私政策》</span>并授权使用您的账号信息以便您统一管理
						</view>
					</health-card-login>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import parse from 'mini-html-parser2'
	import homeApii from '@/api/homee'
	import homeApiii from '@/api/homeee'
	import { reportCmPV } from '../../api/cloudMonitorHelper.js';
	import monitor from '../../api/alipayLogger.js'
	export default {
		data() {
			return {
				showpp: false,
				showw:false,
				wechatCode:"",
				popupShow: false,
				chufulist: [
					"初诊", "复诊"
				],
				value: "0",
				showfu: false,
				showname: false,
				zhentype: "初诊",
				token: "",
				userinfo: "",
				childuserinfo: [
					
				],
				name: "",
				xiadaninfo: "",
				userId:"",
				content:"",
				showText:true,
				log_pic: require('@/static/icons/yimo.png'),
				 columns: [
				                    ['初诊', '复诊']
				                ],
			}
		},
		onLoad(option) {
			reportCmPV({ title: '确认挂号', option });
		
			let token = uni.getStorageSync("token")
			if (token) {
				this.token = token
				this.getuserinfo()
			} else {
				this.gettoken()
			}
			
			let info = uni.getStorageSync("haoinfo")
			this.xiadaninfo = JSON.parse(info)
			this.getwenxin()
		},
		onShow() {


		},
		methods: {
			cancelfu(){
				this.showfu=false
			},
			chossefu(e){
				console.log(e)
				this.zhentype=e.value[0]
				this.showfu=false
			},
			closepopp(){
				this.showfu=false
			},
			toggleDescription() {
				this.showText = !this.showText
				this.$forceUpdate();
			},
			getwenxin(){
				homeApiii.getwen({
					hospitalId:this.xiadaninfo.hospitalId
				}).then(res=>{
					this.content=res.data
					console.log(this.content.length,"123456")
					// if (this.content.length > 100) {
					// 	this.showText = false
					// } else {
					// 	this.showText = true
					// }
				})
			},

			confirm() {
			
					  uni.showLoading({
					  	title: '加载中',
					  	mask: true
					  });
		
				   homeApiii.doorder({
				   	token: this.token,
				   	hospitalId: this.xiadaninfo.hosid,
				   	userId: this.userId,
				   	ghDoctorId: this.xiadaninfo.ghDoctorId,
				   	ghDeptId: this.xiadaninfo.ghDeptId,
				   	guardianId: "",
				   	ext: this.xiadaninfo.ext
				   
				   }).then(res => {
					   
					   	uni.hideLoading()
				   	if (res.code == 4000) {
				   		uni.showToast({
				   			title: "预约成功"
				   		})
				   			let data=res.data
						// let tmplIds=["_yg28izTcpEE0gFQKYWyee1S3Jmjhe1p-5X5ZPDBusE","alPuykMH3d6qkbM9UsPQMo_MAL-Dkdx52hNvak__wTs"]
						let tmplIds=["9rbBRkCU18plcIU_XB1zlFFmAsvu_rbYOuhYDbpmLAU"]
						wx.requestSubscribeMessage({
							tmplIds: tmplIds,
							success(a) {
								console.log(a,"成功")
								uni.setStorageSync("orderinfo",JSON.stringify(data))
								uni.navigateTo({
									url:"/pages/waitpay/waitpay"
								})
							},
							fail(a) {
							// uni.setStorageSync("orderinfo",JSON.stringify(data))
							// uni.navigateTo({
							// 	url:"/pages/waitpay/waitpay"
							// })
							console.log(a,"失败")
						
							}
						})
				   	} else {
				   		uni.showToast({
				   			title: res.msg,
							icon:"none"
				   		})
				   	}
				   
				   })
				
				
			},
			getuserinfo() {
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				homeApii.getuserinfo({
					token: this.token
				}).then(res => {
					console.log(res)
					uni.hideLoading()
					if (res.code == 4000) {
						this.userinfo = res.data.userinfo
						this.childuserinfo = res.data.childuserinfo
						this.userId=this.userinfo.userid
						if (!this.name) {
							this.name = this.userinfo.name
						}
					}

				})
			},
			gettoken() {
				uni.login({
					provider: 'weixin',
					success: (re) => {
						console.log(re)
						let code = res.code
						// this.getopenid()
						const authCode = res.authCode;
						homeApii.getopenid({
							code: code
						}).then(res => {
							console.log(res)
							if (res.code == 4000) {
								uni.setStorageSync("token", res.data.token)
								this.$store.state.doc.token = res.data.token
								this.token = res.data.token
								resovle()
							}
						})
					},
				})
			},
			goxinzneg() {
				this.showname = false
				if (this.wechatCode) {
					uni.navigateTo({
						url: `/pages/mine/addcardd/addcardd?wechatCode=${this.wechatCode}`
					})
				console.log(this.wechatCode)
				} else {
					this.login()
				}
				// uni.navigateTo({
				// 	url:"/pages/mine/addcard/addcard?userid="+this.userinfo.userid
				// })
			},
			hideComponentLogin() {
				this.showw = false
				uni.showLoading()
			},
			login() {
				const plugin = requirePlugin('myPlugin')
				// plugin.login(callback, options)
				plugin.login((isok, res) => {
					console.log('plugin.login: ', isok, res)
					if (res.result.type !== 3) {
						// 用户在微信授权过，可直接获取登录信息，处理后续业务
						this.todo(res)
					} else {
						// 用户未授权，需要用户同意授权
						// 显示 healthCardLogin 登录组件，引导用户同意授权
						this.showw = true
						this.showpp = true
					}
				}, {
					wechatcode: true
				})
			},
			// 业务代码（成功获取登录数据）
			todo(res) {
				// 传入参数 wechatcode = true 结果输出 wechatCode ，注意大小写
				// 传入参数 healthcode = true 及健康卡卡号 ecard_no，输出healthCode
				this.wechatCode = res.result.wechatCode 
			
				if (this.wechatCode) {
					uni.navigateTo({
						url: `/pages/mine/addcardd/addcardd?wechatCode=${this.wechatCode}`
					})
				} else {
					this.login()
				}
			 
			},
			authSuccess(data) {
				uni.hideLoading()
				let res = data.detail
				// 同 plugin.login，用户同意授权，获取登录信息，处理后续业务
				this.todo(res)
			},
			
			// 用户取消授权，授权失败回调
			authCancel() {
				uni.hideLoading()   
			
			},
			closechufu() {
				this.showname = false
			},
			choosechufu() {
				this.showfu = true
				if (this.zhentype == '复诊') {
					this.value = "1"
				}
			},
			closepopchu() {
				this.showfu = false
			},
			confirmchu() {
				this.showfu = false
			},
			onChange(e) {
				let index = e.detail.value[0]
				this.value = index
				let cardt = this.chufulist.find((el) => this.chufulist.indexOf(el) == index)
				this.zhentype = cardt
			},
			closeuser() {
				this.showname = false
				this.popupShow = false
			},
			chooseuser() {
				this.getuserinfo()
				this.showname = true
				this.popupShow = true
			},
			choosechild(item) {
				this.name = item.name
				this.userId=item.userid
				this.showname = false
				this.popupShow = false
			},
			choosefa() {
				this.userId=this.userinfo.userid
				this.name = this.userinfo.name
				this.showname = false
				this.popupShow = false

			},
			close() {
				this.showname = false
				this.popupShow = false
			}
		}
	}
</script>
<style>
	.u-modal__content{
		text-align: center;
	}
	
	
</style>
<style scoped lang="scss">
	.popupShow {
		overflow: hidden;
		position: fixed;
	}
	.pop {
			width: 90%;
			margin: 0 auto;
			overflow: hidden;
			margin-top: 150rpx;
			padding-bottom: 30rpx;
		
			.poptop {
				width: 100%;
			}
		
			.cardimg {
				width: 150rpx;
				height: 150rpx;
				margin: 0 auto;
				margin-top: 10rpx;
		
				image {
					width: 100%;
					height: 100%;
				}
			}
		
			.hosname {
				width: 95%;
				margin: 0 auto;
				text-align: center;
				font-size: 50rpx;
				font-weight: bold;
				margin-top: 80rpx;
			}
		
		
		
			.title {
				width: 100%;
				text-align: center;
				margin-top: 18rpx;
				font-size: 32rpx;
				color: #333;
				font-weight: 550;
			}
		
			.info {
				width: 80%;
				margin: 0 auto;
				margin-top: 10rpx;
				font-size: 28rpx;
			}
		
			.shuomingg {
				width: 95%;
				margin: 0 auto;
				font-size: 28rpx;
				color: #999;
				line-height: 40rpx;
				margin-top: 80rpx;
		
				span {
					color: orange;
				}
		
			}
		
			.foott {
				width: 80%;
				margin: 0 auto;
				display: flex;
				// margin-top: 20rpx;
				justify-content: space-between;
		
		
		
				.agree {
					width: 80%;
					height: 90rpx;
					margin: 0 auto;
					font-size: 34rpx;
					color: #fff;
					border-radius: 90rpx;
					line-height: 90rpx;
					text-align: center;
					background-color: #3669F8;
					margin-top: 100rpx;
				}
			}
		}
	.confirm {
		width: 100%;
		background-color: #F5F6F8;
		padding-bottom: 220rpx;
		overflow: hidden;
		padding-top: 180rpx;

		.btnlist {
			width: 95%;
			margin: 0 auto;
			display: flex;
			justify-content: space-between;
			line-height: 100rpx;
			font-size: 30rpx;

			.btnl {
				color: #888;
			}

			.btnr {
				color: #4581F6;
			}
		}

		.popuser {
			padding-top: 20rpx;
			padding-bottom: 20rpx;

			.userlist {
				.useritem {
					text-align: center;
					font-size: 26rpx;
					line-height: 80rpx;
				}
			}

			.line {
				width: 100%;
				height: 15rpx;
				background-color: #F5F6F8;
			}

			.add {
				text-align: center;
				font-size: 26rpx;
				line-height: 80rpx;
				border-bottom: 1px solid #f7f7f7;
			}

			.cancel {
				text-align: center;
				font-size: 26rpx;
				line-height: 80rpx;
			}
		}

		.btn {
			width: 93%;
			margin: 0 auto;
			margin-top: 20rpx;
			border-radius: 15rpx;
			line-height: 80rpx;
			border-radius: 40rpx;
			background-color: #4581F6;
			color: #fff;
			text-align: center;

		}

		.wenxin {
			width: 93%;
			margin: 0 auto;
			margin-top: 20rpx;
			padding-top: 20rpx;
			padding-bottom: 20rpx;
			font-size: 24rpx;
			line-height: 40rpx;
			color: #3D3D3D;
			.full_text {
				display: flex;
				font-size: 28rpx;
				line-height: 40rpx;
				margin-left: 44%;
				color: #4581F6;
			}
		}

		.jiuxin {
			width: 93%;
			margin: 0 auto;
			margin-top: 20rpx;
			border-radius: 15rpx;
			background-color: #fff;
			padding-top: 20rpx;
			padding-bottom: 20rpx;

			.jiuxinmain {
				width: 95%;
				margin: 0 auto;

				.jiuxinitem {
					display: flex;
					justify-content: space-between;
					line-height: 80rpx;
					font-size: 26rpx;

					.xiniteml {
						color: #666;
					}

					.xinitemr {
						color: #555;
					}

				}
			}
		}

		.jiuinfo {
			width: 93%;
			margin: 0 auto;
			margin-top: 20rpx;
			border-radius: 15rpx;
			background-color: #fff;
			padding-top: 20rpx;
			padding-bottom: 20rpx;

			.jiumain {
				width: 95%;
				margin: 0 auto;

				.jiuitem {
					border-bottom: 1rpx solid #f7f7f7;
					padding-bottom: 10rpx;
					padding-top: 10rpx;

					.jiutit {
						font-size: 26rpx;
						color: #666666;
						line-height: 50rpx;
					}

					.jiui {
						font-size: 32rpx;
						color: #333;
						line-height: 50rpx;
						font-weight: 400;
					}
				}
			}
		}

		.docinfo {
			width: 93%;
			margin: 0 auto;
			margin-top: 20rpx;
			border-radius: 15rpx;
			background-color: #fff;
			padding-top: 20rpx;
			padding-bottom: 20rpx;

			.docmain {
				width: 95%;
				margin: 0 auto;
				display: flex;

				.docl {
					width: 88rpx;
					height: 88rpx;
					border-radius: 50%;

					image {
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}
				}

				.docr {
					margin-left: 20rpx;

					.docname {
						font-size: 28rpx;
						font-weight: 400;
						line-height: 40rpx;
						color: #3D3D3D;

						span {
							font-size: 24rpx;
							margin-left: 15rpx;
							color: #888888;
						}
					}

					.hosname {
						font-size: 24rpx;
						line-height: 40rpx;
						color: #3D3D3D;
					}
				}
			}

		}
	}
</style>
